<?php
// +----------------------------------------------------------------------
// | 众联TK架构 [ ZoomTk ]
// +----------------------------------------------------------------------
// | 版权所有 2017~2037 成都众联思索科技有限公司 [ http://www.zoomtk.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://www.sopvip.com
// +----------------------------------------------------------------------
// | 开源协议 ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------

namespace app\mall\admin;
use app\common\builder\TKuitpl;
use app\mall\common\Adminbase;
use think\Model;
use think\Cache;
use think\Db;

/**
 * 商家管理中心
 * @package app\mall\admin
 */
class Bill extends Adminbase
{
    /**
     * 首页
     * @author Sunday <153788231@qq.com>
     * @return mixed
     */
    public function index()
    {
        $model_bill = Model('bill');
        $condition = array();
//        list($condition,$order) = $this->_get_bill_condition($condition);
        $order='';
        $bill_list = $model_bill->getOrderBillList($condition,'*',$order);
        $data = array();
        $page= $bill_list->render();
        foreach ($bill_list as $bill_info) {
            $list = array();
            if (in_array($bill_info['ob_state'],array(2,3))) {
                $list['operation'] = "<a class=\"btn orange\" href=\"index.php?s=bill&op=show_bill&ob_id={$bill_info['ob_id']}\"><i class=\"fa fa-gavel\"></i>处理</a>";
            } else {
                $list['operation'] = "<a class=\"btn green\" href=\"index.php?s=bill&op=show_bill&ob_id={$bill_info['ob_id']}\"><i class=\"fa fa-list-alt\"></i>查看</a>";
            }
            $list['ob_id'] = $bill_info['ob_id'];
            $list['ob_order_totals'] = PriceFormat($bill_info['ob_order_totals']);
            $list['ob_shipping_totals'] = PriceFormat($bill_info['ob_shipping_totals']);
            $list['ob_commis_totals'] = PriceFormat($bill_info['ob_commis_totals']);
            $list['ob_order_return_totals'] = PriceFormat($bill_info['ob_order_return_totals']);
            $list['ob_commis_return_totals'] = PriceFormat($bill_info['ob_commis_return_totals']);
            $list['ob_store_cost_totals'] = PriceFormat($bill_info['ob_store_cost_totals']);
            $list['ob_result_totals'] = PriceFormat($bill_info['ob_result_totals']);
            $list['ob_create_date'] = date('Y-m-d',$bill_info['ob_create_date']);
            $list['ob_state'] = billState($bill_info['ob_state']);
            $list['ob_store_name'] = $bill_info['ob_store_name'];
            $list['ob_start_date'] = date('Y-m-d',$bill_info['ob_start_date']);
            $list['ob_end_date'] = date('Y-m-d',$bill_info['ob_end_date']);
            $list['ob_store_id'] = $bill_info['ob_store_id'];
            $data[$bill_info['ob_id']] = $list;
        }
        // 使用TKuitpl快速创建数据表格
        return TKuitpl::make('table')
            ->setPageTitle('结算管理')// 设置页面标题
            ->setPrimaryKey('type_id') // 设置主键名为username
            ->setSearch(['type_id' => '类型ID', 'type_name' => '类型名称'])// 设置搜索参数
            ->addOrder('type_id,type_name') // 添加排序
            ->addColumns([ // 批量添加列
                ['ob_id', '账单编号'],
                ['ob_order_totals', '订单金额'],
                ['ob_commis_totals', '收取佣金'],
             //   ['class_id', '退单金额'],
                ['class_id', '本期结算'],
                ['class_name', '出账日期'],
                ['ob_store_id', '商家ID'],
                ['ob_store_name', '商家名称'],
                ['right_button', '操作', 'btn']
            ])
            ->addRightButtons('edit,delete')// 批量添加右侧按钮
            ->setRowList($data)// 设置表格数据
            ->setPages($page)// 设置分页数据
            ->fetch(); // 渲染页面
    }
}


